package com.softer.wxzj.controller;


import com.github.pagehelper.PageInfo;
import com.softer.wxzj.common.aop.annotation.LogRecord;
import com.softer.wxzj.common.aop.enums.LogOperationType;
import com.softer.wxzj.common.aop.enums.LogOperationUnit;
import com.softer.wxzj.common.entity.CommonResult;
import com.softer.wxzj.common.entity.Page;
import com.softer.wxzj.entity.FlowConfig;
import com.softer.wxzj.service.FlowConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * FlowConfigController class
 *
 * @author zcz
 * @date 2019/1/16
 */
@RestController
@RequestMapping("/flowConfig")
@Slf4j
public class FlowConfigController {
    @Autowired
    FlowConfigService flowConfigService;


    /**
     * 新增配置
     *
     * @param configList \配置集合
     * @return 处理结果
     */
    @PostMapping("/replace")
    @LogRecord(description = "审批配置替换", operationUnit = LogOperationUnit.FLOW_CONFIG, operationType = LogOperationType.REPLACE)
    public CommonResult replace(@RequestBody List<FlowConfig> configList) {
        return flowConfigService.replace(configList);
    }

    /**
     * 审批配置修改
     *
     * @param flowConfig
     * @return
     */
    @PostMapping("/update")
    @LogRecord(description = "审批配置修改", operationUnit = LogOperationUnit.FLOW_CONFIG, operationType = LogOperationType.UPDATE)
    public CommonResult update(FlowConfig flowConfig) {
        return flowConfigService.update(flowConfig);
    }

    /**
     * 审批配置删除
     *
     * @param id
     * @return
     */
    @PostMapping("/delete")
    @LogRecord(description = "审批配置删除", operationUnit = LogOperationUnit.FLOW_CONFIG, operationType = LogOperationType.DELETE)
    public CommonResult delete(String id) {
        return flowConfigService.delete(id);
    }

    /**
     * 审批配置查询列表
     *
     * @param page
     * @param flowConfig
     * @return
     */
    @PostMapping("/getList")
    @LogRecord(description = "审批配置查询列表", operationUnit = LogOperationUnit.FLOW_CONFIG, operationType = LogOperationType.SELECT)
    public PageInfo<FlowConfig> getRoleList(Page page, FlowConfig flowConfig) {
        return flowConfigService.getList(page, flowConfig);
    }

    /**
     * 查询配置列表,配置进度条
     *
     * @param flowType
     * @return
     */
    @PostMapping("/getConfigListByFlowType")
    @LogRecord(description = "查询配置列表,配置进度条", operationUnit = LogOperationUnit.FLOW_CONFIG, operationType = LogOperationType.SELECT)
    public List<FlowConfig> getConfigListByFlowType(@RequestParam("flowType") String flowType) {
        return flowConfigService.getConfigListByFlowType(flowType);
    }

    /**
     * 查询当前配置,配置进度条
     *
     * @param businessId
     * @return
     */
    @PostMapping("/getCurrentConfigByBusinessId")
    @LogRecord(description = "查询当前配置,配置进度条", operationUnit = LogOperationUnit.FLOW_CONFIG, operationType = LogOperationType.SELECT)
    public FlowConfig getCurrentConfigByBusinessId(@RequestParam("businessId") String businessId, @RequestParam("flowType") String flowType) {
        return flowConfigService.getCurrentConfigByBusinessId(businessId, flowType);
    }

    /**
     * 查询审批或备案展示状态
     *
     * @param flowType
     * @return
     */
    @PostMapping("/getOperFlagByFlowType")
    @LogRecord(description = "查询审批或备案展示状态", operationUnit = LogOperationUnit.FLOW_CONFIG, operationType = LogOperationType.SELECT)
    public int getOperFlagByFlowType(@RequestParam("flowType") String flowType) {
        return flowConfigService.getOperFlagByFlowType(flowType);
    }

    /**
     * 查询申请人
     *
     * @param businessId 业务ID
     * @param flowType   类型
     * @return 申请人
     */
    @PostMapping("/getApplicant")
    @LogRecord(description = "查询申请人", operationUnit = LogOperationUnit.FLOW_CONFIG, operationType = LogOperationType.SELECT)
    public String getApplicant(@RequestParam("businessId") String businessId, @RequestParam("flowType") String flowType) {
        return flowConfigService.getApplicant(businessId, flowType);
    }
}
